class ApplicationController < ActionController::Base

  protect_from_forgery
    def check_access(role, redirect_url=root_path, msg=t('access.errors.denied'))
      if signed_in?
        return if current_user.role?(role)
      else
        msg = t('access.errors.not_logged_in')
      end

      respond_to do |format|
        format.html { redirect_to redirect_url, :alert => msg }
        format.js { render :js => "ShowNotify('#{msg}', 'alert');" }  # TODO status 200?
      end
    end

    def check_moderators_access
      check_access "#{controller_name}_moderator".to_sym
    end
end
